﻿using System.Configuration;
using System.Net.Http;
using System.Threading.Tasks;

namespace Utils
{
    public class Utilities
    {
        public async static Task<byte[]> GetResponse(string url)
        {
            byte[] data = null;
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    await client.GetAsync(url).ContinueWith(t =>
                    {
                        if (t.IsFaulted)
                        {
                            throw t.Exception.Flatten();
                        }

                        data = t.Result.Content.ReadAsByteArrayAsync().Result;
                    });
                }
                catch (System.Exception)
                {
                    throw;
                }
            }
            return data;
        }
    }
}
